package com.example.forum.controller;

import com.example.forum.entity.Board;
import com.example.forum.result.Result;
import com.example.forum.services.impl.BoardServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/board")
@Tag(name = "板块接口")
public class BoardController {

    @Value("${bit-forum.index.board-size}")
    private Integer boardSize;

    @Autowired
    private BoardServiceImpl boardService;

    /**
     * 获取板块列表
     *
     * @return
     */
    @Operation(summary = "板块列表")
    @GetMapping("/topList")
    public Result<List<Board>> getList() {
        List<Board> list = boardService.getList(boardSize);
        return Result.success(list);
    }

    /**
     * 获取板块信息
     *
     * @param boardId
     * @return
     */
    @Operation(summary = "获取板块信息")
    @GetMapping("/getById")
    public Result<Board> getById(@Parameter(description = "板块id") @RequestParam(value = "id") Long boardId) {
        Board board = boardService.getById(boardId);
        return Result.success(board);
    }
}
